package com.huarui.desktop;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.huarui.desktop.model.ModuleScript;
import com.huarui.desktop.model.ModuleScriptDesc;
import com.huarui.desktop.service.ModuleScriptBuilder;
import com.huarui.desktop.service.ModuleScriptDesigner;
import com.huarui.user.model.SessionMessage;
import com.huarui.user.security.UserHolder;

public class DesktopTester {

	static ClassPathXmlApplicationContext context;

	@BeforeClass
	public static void initContext() {

		context = new ClassPathXmlApplicationContext(new String[] { "spring/spring-framework.xml", "spring/spring-desktop.xml" });

	}

	@Before
	public void setUp() throws Exception {

		initContext();
		SessionMessage sm = new SessionMessage();
		sm.setUserId(100);
		sm.setCompanyId(100100);

		UserHolder.setCurrenSessionMessage(sm);
	}

	@Test
	public void testGenerateJs() {
		ModuleScriptDesc desc = new ModuleScriptDesc("task");
		desc.setWinTitle("我的任务");
		desc.setWinId("taskListWin");
		desc.setWinIconCls("acc-icon");
		desc.setWinClassName("Uec3.TaskListWindow");
		ModuleScriptDesigner moduleScriptDesigner = (ModuleScriptDesigner) context.getBean("moduleScriptDesigner");
		ModuleScriptBuilder moduleScriptBuilder = (ModuleScriptBuilder) context.getBean("moduleScriptBuilder");
		moduleScriptDesigner.order(desc, moduleScriptBuilder);
		ModuleScript moduleScript = moduleScriptBuilder.getModuleScript();

		String result = moduleScript.description();

		System.out.println("==" + result);
	}

	public static void main(String[] rags) {
		DesktopTester.initContext();
		DesktopTester tester = new DesktopTester();
		tester.testGenerateJs();

	}
}
